package com.wxyzz.canteenadmin.goods.stockControl.controller;

import com.github.pagehelper.PageInfo;
import com.wxyzz.canteenadmin.goods.stockControl.param.StockControlDataParam;
import com.wxyzz.canteenadmin.goods.stockControl.param.StockControlVueParam;
import com.wxyzz.canteenadmin.goods.stockControl.service.StockControlService;
import com.wxyzz.canteenadmin.goods.stockControl.vo.StockControlVo;
import com.wxyzz.canteencommon.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods/stockControl")
public class StockController {
    @Autowired
    private StockControlService stockControlService;
    //查询  展示所有的数据，分页，模糊查询
    @GetMapping("/pageStockControl")
    public R pageStockControl(StockControlVueParam stockControlVueParam){
        PageInfo<StockControlVo> allStockControl = stockControlService.findAllStockControl(stockControlVueParam);
        return  R.ok(allStockControl);
    }
    //添加  添加商品分类信息
    @PostMapping("/addStockControl")
    public R addStockControl(@RequestBody StockControlVueParam stockControlVueParam){
        stockControlService.saveStockControl(stockControlVueParam);
        return  R.ok();
    }
    //修改  在修改前先通过id进行查询展示当前行的信息
    @GetMapping("/findStockControlById")
    public R findStockControlById(int id){
        StockControlDataParam stockControlById = stockControlService.findStockControlById(id);
        return  R.ok(stockControlById);
    }
    //修改  修改商品分类信息
    @PostMapping("/updateStockControl")
    public R updateStockControl(@RequestBody StockControlVueParam stockControlVueParam){
        stockControlService.UpdateStockControl(stockControlVueParam);
        return  R.ok();
    }
    //删除数据 根据id删除
    @GetMapping("/delStockControl")
    public R delStockControl(int id){
        stockControlService.deleteStockControlById(id);
        return  R.ok();
    }
    //删除数据 批量删除
    @GetMapping("/delBatchStockControl")
    public R delBatchStockControl(@RequestParam List<Integer> ids){
        System.out.println("@@@@@@@@@@@@@@@@@@@@==>>"+ids);
        stockControlService.delBatchStockControlById(ids);
        return  R.ok();
    }
}
